#!/usr/bin/perl
#

my $optie1 = $ARGV[0];
my $optie2 = $ARGV[1];
my $optie3 = $ARGV[2];
use strict;
use Net::DNS;

sub zoneTransfer {
  my $zone =  "@_[0]";
  my $res = Net::DNS::Resolver->new(
    nameservers => [qw(127.0.0.1)],
  );
  $res->tcp_timeout(10);
  my @zone = $res->axfr($zone);
  if (@zone) {
    foreach my $rr (@zone) {
      $rr->print;
    }
  } else {
    print 'Zone transfer failed: ', $res->errorstring, "\n";
  }
}

# class ptrdname cname dname 
# info ophalen door grep self *.pm | grep Net::DNS in Net/DNS/RR directory
sub query {
  my $question =  "@_[0]";
  my $res = Net::DNS::Resolver->new(
    nameservers => [qw(127.0.0.1)],
  );
  my $answer = $res->search($question);
  if ($answer) {
    foreach my $rr ($answer->answer) {
      my $type = $rr->type;
      if ( "$type" eq "A" ) {
        my $address = $rr->address;
        print("$question has address $address\n");
      } elsif ( "$type" eq "PTR" ) {
        my $ptrdname = $rr->ptrdname;
	print("$question domain name pointer $ptrdname\n");
      }
    }
  } else {
    my $error = $res->errorstring;
    print("query failed: $error \n");
  }
}

if ( "$optie1" eq "-l" ) {
  zoneTransfer($optie2);
} else {
  query( $optie1, $optie2 );
}

